<template>
    <h2>修改</h2>
    <table border="1">
        <tr>
            <td>科室名称</td>
            <ts>
                <input type="text" v-model="info.D_Name"/>
            </ts>
        </tr>
        <tr>
            <td>科室介绍</td>
            <ts>
                <input type="text" v-model="info.D_Info"/>
            </ts>
        </tr>
        <tr>
            <td>
                <input type="button" value="修改" @click="Add"/>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useCounterStore} from '../stores/counter.ts';
    const Cstore=useCounterStore();
    import {useRoute,useRouter} from 'vue-router';
    const route=useRoute();
    const router=useRouter();

    onMounted(()=>{
        Fanti();
    })

    const info=ref({
        D_Id: route.params.id,
        D_Name: "",
        D_Info: ""
    });

    const Add=()=>{
        axios.put("https://localhost:7010/api/Dept/UpdateDept",info.value)
        .then(res=>{
            if(res.data>0){
                alert('修改成功');
                router.push({
                    name:"ShowDept"
                })
            }
            else{
                alert('修改失败');
            }
        })
    }



    const Fanti=()=>{
        axios.get("https://localhost:7010/api/Dept/FanTian",{
            params:{
                id:route.params.id
            }
        })
        .then(res=>{
            info.value=res.data;
        })
        .catch(err=>{
            console.log(err);
        })
    }

</script>
